
''Require that all variables be declared
Option Explicit

''======================================================
'' Main Program:ParseText
'' Desc:       Reads a text file into a variable then
''             writes it into a row, n chars at a time
'' Called by:  user
'' Call:
'' Arguments:
'' Comments:   Written quickly. No error-checking.
'' Changes----------------------------------------------
'' Date        Programmer     Change
'' 12/11/2019      Charley Kyd    Written
''======================================================
Sub ParseText()
   Dim sText As String, sFile As String

   ''Get the full path to the source file
   With ThisWorkbook
      sFile = .Names("SourcePath").RefersToRange
      If Left(sFile, 1) <> "\" Then sFile = sFile & "\"
      sFile = sFile & .Names("SourceFile").RefersToRange
   End With

   ''Get the full text string from the text file
  sText = GetText(sFile)

   ''Remove all nonprintable characters from the text
   ''Comment out if the characters are wanted
   sText = Excel.WorksheetFunction.Clean(sText)

   ''Write to the workbook
   WriteToSheet sText
End Sub


main Program
	Sub AddChartTitle()
'PURPOSE: Add a title to a specific chart

Dim cht As ChartObject

Set cht = ActiveSheet.ChartObjects("Chart 1")

'Ensure chart has a title
  cht.Chart.HasTitle = True

'Change chart's title
  cht.Chart.ChartTitle.Text = "My Graph"

End Sub
 
 Sub-Program 
 Sub RepositionChartTitle()
'PURPOSE: Reposition a chart's title

Dim cht As ChartObject

Set cht = ActiveSheet.ChartObjects("Chart 1")

'Reposition title
  With cht.Chart.ChartTitle
    .Left = 100
    .Top = 50
  End With
  Sub-Program
  Sub InsertChartLegend()

Dim cht As Chart

Set cht = ActiveSheet.ChartObjects("Chart 1").Chart

'Add Legend to the Right
  cht.SetElement (msoElementLegendRight)
  
'Add Legend to the Left
  cht.SetElement (msoElementLegendLeft)
  
'Add Legend to the Bottom
  cht.SetElement (msoElementLegendBottom)
  
'Add Legend to the Top
  cht.SetElement (msoElementLegendTop)
  
'Add Overlaying Legend to the Left
  cht.SetElement (msoElementLegendLeftOverlay)
  
'Add Overlaying Legend to the Right
  cht.SetElement (msoElementLegendRightOverlay)

End Sub
''======================================================
'' Program:    GetText
'' Desc:       Read a text file into a string and then
''             return the string
'' Called by:  ParseText
'' Call:       GetText(sFile)
'' Arguments:  sFile--The full path to the text file
'' Comments:
'' Changes----------------------------------------------
'' Date      Programmer   Change
'' 12/11/2019   Charley Kyd  Written
''======================================================
Function GetText(sFile As String) As String
   Dim nSourceFile As Integer, sText As String

   ''Close any open text files
   Close

   ''Get the number of the next free text file
   nSourceFile = FreeFile

   ''Write the entire file to sText
   Open sFile For Input As #nSourceFile
   sText = Input$(LOF(1), 1)
   Close

   GetText = sText
End Function

''======================================================
'' Program:    WriteToSheet
'' Desc:       Writes a text string to one row of a
''             worksheet, n characters per column
'' Called by:  ParseText
'' Call:       WriteToSheet sText
'' Arguments:  sText--String with text from text file
'' Comments:   This routine will throw an error if the
''             text is too long to fit within 256 columns
'' Changes----------------------------------------------
'' Date      Programmer   Change
Subprograms 
'' 12/11/2019   
''======================================================
Sub WriteToSheet(sText As String)
   Dim sTgtSheet As String, nTgtRow As Integer
   Dim nColCount As Integer, sChunk As String
   Dim nIncrement As Integer, rngRef As Range

   ''Get the controlling variables
   With ThisWorkbook
      sTgtSheet = .Names("TargetSheet").RefersToRange
      nTgtRow = .Names("TargetRow").RefersToRange
      nIncrement = .Names("Increment").RefersToRange

      Set rngRef = Worksheets(sTgtSheet).Cells(nTgtRow, 1)
   End With

   ''Erase any previous entries
   rngRef.EntireRow.ClearContents

   ''Initialize the column counter
   nColCount = 0

   ''Loop thru the string, grabbing text of specified
   ''length, writing the text to the spreadsheet
   Do
      ''Increment the column count
      nColCount = nColCount + 1
      ''Grab the current chunk of text
      sChunk = Mid$(sText, 1 + (nColCount - 1) * _
          nIncrement, nIncrement)
      ''Write it to the spreadsheet
      rngRef.Cells(1, nColCount) = sChunk

      ''Stop after writing a partial chunk
   Loop Until Len(sChunk) < nIncrement
End Sub